package com.lx.web;

import com.lx.entity.Admin;
import com.lx.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class myAdminServlet {
    @Autowired
    private AdminService adminService;

    //跳转到查询页面
    @RequestMapping("/toAdmin")
    public String toAdmin(){
        return "/WEB-INF/jsp/admin.jsp";
    }

    //跳转到修改页面
    @RequestMapping("/toUpdateAdmin")
    public String toUpdateUser(){
        return "/WEB-INF/jsp/updateAdminPassword.jsp";
    }

    //修改密码
    @RequestMapping("/updateAdmin")
    public String updateAdmin(int id, String name, String oldPassword,String passwords,String password,HttpServletRequest request){
        Admin admin = new Admin(id, name, password);
        boolean b = adminService.updateAdmin(admin, oldPassword,passwords);
        if (b){
            request.getSession().setAttribute("admin",admin);
            return "redirect:/toAdmin";
        }else {
            return "/toUpdateAdmin";
        }
    }
}
